package com.maben.mybatis.controller;

import com.maben.mybatis.pojo.Classes;
import com.maben.mybatis.service.ClassesService;
import com.maben.mybatis.service.MyService;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 测试控制类
 */
@RestController
public class TestController {
    @Resource
    private MyService myService;
    @Resource
    private ClassesService classesService;

    /**
     * 测试创建表
     */
    @RequestMapping("createTable")
    public Map<String, Object> createTable(String tableName) {
        final Map<String, Object> result = new HashMap<>();
        result.put("code", "0");
        try {
            myService.createTable(tableName);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", "-1");
            result.put("msg", ExceptionUtils.getStackTrace(e));
        }
        return result;
    }

    /**
     * 测试单表
     */
    @RequestMapping("queryClassesSelective0")
    public  Map<String, Object> queryClassesSelective0(){
        final Map<String, Object> result = new HashMap<>();
        result.put("code", "0");
        try {
            final Map<String,Object> cxMap = new HashMap<>();
            final List<Classes> classesList = classesService.queryClassesSelective0(cxMap);
            result.put("data", classesList);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", "-1");
            result.put("msg", ExceptionUtils.getStackTrace(e));
        }
        return result;
    }

    /**
     * 测试一对一
     */
    @RequestMapping("queryClassesSelective1")
    public  Map<String, Object> queryClassesSelective1(){
        final Map<String, Object> result = new HashMap<>();
        result.put("code", "0");
        try {
            final Map<String,Object> cxMap = new HashMap<>();
            final List<Classes> classesList = classesService.queryClassesSelective1(cxMap);
            result.put("data", classesList);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", "-1");
            result.put("msg", ExceptionUtils.getStackTrace(e));
        }
        return result;
    }
    /**
     * 测试一对多
     */
    @RequestMapping("queryClassesSelective2")
    public  Map<String, Object> queryClassesSelective2(){
        final Map<String, Object> result = new HashMap<>();
        result.put("code", "0");
        try {
            final Map<String,Object> cxMap = new HashMap<>();
            final List<Classes> classesList = classesService.queryClassesSelective2(cxMap);
            result.put("data", classesList);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", "-1");
            result.put("msg", ExceptionUtils.getStackTrace(e));
        }
        return result;
    }



}
